import 'package:flutter/material.dart';
import 'package:flutter_saixiaoli/pages/home/active.dart';
import 'package:flutter_saixiaoli/pages/home/classif.dart';
import 'package:flutter_saixiaoli/pages/home/liveWidget.dart';
import 'package:flutter_saixiaoli/pages/home/match.dart';
import 'package:flutter_saixiaoli/pages/home/selected.dart';
import 'package:flutter_saixiaoli/pages/home/tabs.dart';
import 'package:flutter_saixiaoli/pages/home/underlinePainter.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class Home extends StatefulWidget {
  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
  List tabs = [
    {'name': '新手入门'},
    {'name': '亲子夏令营'},
    {'name': '自驾游'}
  ];

  List classification = [
    {'image': 'images/home/tab1.png', 'text': '赛事活动'},
    {'image': 'images/home/tab2.png', 'text': '户外旅游'},
    {'image': 'images/home/tab3.png', 'text': '精选商城'},
    {'image': 'images/home/tab4.png', 'text': '相册直播'},
    {'image': 'images/home/tab5.png', 'text': '成绩查询'},
  ];
  List swiper = [
    {'active': false, 'num': '1000'},
    {'active': true, 'num': '2000'}
  ];
  TabController tabc;
  int tabIndex = 0;

  List tabbarViewData = [
    {
      'city': '合肥',
      'day': '3',
      'chengxing': false,
      'title': '徽杭古道2日游驴友徒步+景点路线',
      'subtitle': '10月-11月/共3期',
      'price': '500'
    },
    {
      'city': '南京',
      'day': '5',
      'chengxing': true,
      'title': '安徽黄山+宏村 5日游跟团游 +景点路线',
      'subtitle': '10月-11月/共3期',
      'price': '600'
    },
    {
      'city': '上海',
      'day': '7',
      'chengxing': false,
      'title': '徽杭古道2日游驴友徒步+景点路线',
      'subtitle': '10月-11月/共3期',
      'price': '700'
    },
    {
      'city': '北京',
      'day': '5',
      'chengxing': true,
      'title': '安徽黄山+宏村 5日游跟团游 +景点路线',
      'subtitle': '10月-11月/共3期',
      'price': '900'
    },
  ];
  @override
  void initState() {
    super.initState();
    tabc = new TabController(length: tabs.length, vsync: this);
    tabc.addListener(() {
      setState(() {
        tabIndex = tabc.index;
      });
    });
  }

  EdgeInsets pd_12 = EdgeInsets.symmetric(horizontal: 12);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('首页'),
          elevation: 0,
          centerTitle: true,
        ),
        body: SingleChildScrollView(
          child: Container(
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 12),
                  child: Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        color: Colors.red),
                    width: MediaQuery.of(context).size.width,
                    height: 150,
                  ),
                ),
                Container(
                  margin: EdgeInsets.symmetric(vertical: 15, horizontal: 12),
                  child: Row(
                    children: [
                      Container(
                        child: Image.asset(
                          'images/home/news.png',
                          width: 15,
                          height: 15,
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 10),
                        child: Image.asset(
                          'images/home/text.png',
                          width: 50,
                          height: 12,
                        ),
                      ),
                      Container(
                        width: 0.5,
                        height: 12,
                        color: Color.fromRGBO(153, 153, 153, 1),
                        margin: EdgeInsets.symmetric(horizontal: 10),
                      ),
                      Container(
                        child: Text(
                          '恭喜带你飞跑团成功获奖！',
                          style: TextStyle(
                              color: Color.fromRGBO(102, 102, 102, 1),
                              fontSize: 12),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Color.fromRGBO(249, 249, 249, 1),
                  height: 8,
                ),
                //分类
                Classif(
                  classification: classification,
                ),
                //live
                Live(
                  swiper: swiper,
                ),
                Column(
                  children: [
                    //tabs
                    Tabs(
                        tabc: tabc, tabs: tabs, tabbarViewData: tabbarViewData),
                    Container(
                      width: MediaQuery.of(context).size.width,
                      height: 8,
                      color: Color.fromRGBO(246, 246, 246, 1),
                    ),
                    //赛事
                    Match(),
                    Container(
                      margin: EdgeInsets.only(top: 10),
                      height: 8,
                      color: Color.fromRGBO(249, 249, 249, 1),
                    ),
                    //精选游记
                    Selected(),
                    //活动
                    Active()
                  ],
                ),
              ],
            ),
          ),
        ));
  }
}
